package com.shark.manager.system.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shark.commons.web.BaseController;
import com.shark.commons.web.model.AjaxResponse;
import com.shark.commons.web.model.DataGrid;
import com.shark.manager.system.model.User;
import com.shark.manager.system.service.UserService;

@Controller
@RequestMapping("/manager/system/user")
public class UserController extends BaseController {
	
	@Autowired
	private UserService service ;

	/**
	 * 主页
	 * @return
	 */
	@RequestMapping(value="/main", method=RequestMethod.GET)
	public String main(Model model) {
		return viewName("main") ;
	}
	
	/**
	 * 表单页面
	 * @param id
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/form", method=RequestMethod.GET)
	public String form(Long id, Model model) {
		if(null != id) {
			model.addAttribute("id", id) ;
		}
		return viewName("form") ;
	}
	
	/**
	 * 添加
	 * @param dto
	 * @return
	 */
	@RequestMapping(value="/add", method=RequestMethod.POST)
	public @ResponseBody AjaxResponse add(User dto) {
		return this.service.add(dto);
	}
	
	/**
	 * 删除
	 * @param ids 数组
	 * @return
	 */
	@RequestMapping(value="/deleteBatch", method=RequestMethod.POST)
	public @ResponseBody AjaxResponse deleteBatch(Long[] ids) {
		return this.service.deleteBatchByKeys(ids) ;
	}
	
	/**
	 * 修改
	 * @param dto
	 * @return
	 */
	@RequestMapping(value="/update", method=RequestMethod.POST)
	public @ResponseBody AjaxResponse update(User dto) {
		return this.service.update(dto);
	}
	
	/**
	 * 根据ID获取数据
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/get/{id}", method=RequestMethod.GET)
	public @ResponseBody User get(@PathVariable Long id) {
		return this.service.selectByPrimaryKey(id) ;
	}
	
	/**
	 * 分页列表
	 * @param dto
	 * @return
	 */
	@RequestMapping(value="/datagrid", method=RequestMethod.GET)
	public @ResponseBody DataGrid<User> datagrid(User dto) {
		return this.service.datagrid(dto) ;
	}
	
	/**
	 * 重置密码窗口
	 * @return
	 */
	@RequestMapping(value="/resetPassword_dialog", method=RequestMethod.GET)
	public String resetPassword_dialog() {
		return viewName("resetPassword_dialog") ;
	}
	
	/**
	 * 重置密码
	 * @param password
	 * @param user_ids
	 * @return
	 */
	@RequestMapping(value="/resetPassword", method=RequestMethod.POST)
	public @ResponseBody AjaxResponse resetPassword(String password, Long[] ids) {
		return this.service.resetPassword(password, ids) ;
	}
	
}
